//
//  CustNaviBarView.m
//  EasyToTesco2.0
//
//  Created by 杨森 on 2017/5/18.
//  Copyright © 2017年 EasyToTesco. All rights reserved.
//

#import "CustNaviBarView.h"

@interface  CustNaviBarView()

@property(nonatomic,strong)UIView    *contenView;

@property(nonatomic,strong)UIButton  *chatBtn;
@property(nonatomic,strong)UIButton  *searchBtn;
@property(nonatomic,strong)UIButton  *locationBtn;

@end

@implementation CustNaviBarView


- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self buildView];
    }
    return self;
}

- (void)buildView
{
    [self addSubview:self.contenView];
    [self.contenView addSubview:self.chatBtn];
    [self.contenView addSubview:self.searchBtn];
    [self.contenView addSubview:self.locationBtn];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    WeakSelf(self);
//    [self.chatBtn mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.centerY.equalTo(weakself.contenView);
//        make.right.equalTo(weakself.contenView.mas_right).offset(-20);
//    }];
    
    [self.searchBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(weakself.contenView);
        make.height.mas_equalTo(32);
        make.width.mas_equalTo(self.width/5*3);
    }];
    
    [self.locationBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(weakself.contenView);
        make.left.equalTo(weakself.contenView.mas_left).offset(20);
    }];
}

- (void)setLocationStr:(NSString *)locationStr
{
    _locationStr = locationStr;
    [self.locationBtn setTitle:locationStr forState:UIControlStateNormal];
}

- (void)setSearchStr:(NSString *)searchStr
{
    _searchStr = searchStr;
    [self.searchBtn setImage:[UIImage imageNamed:searchStr] forState:UIControlStateNormal];
    [self.searchBtn setImage:[UIImage imageNamed:searchStr] forState:UIControlStateHighlighted];
}


#pragma mark lazy
- (UIView *)contenView
{
    if (!_contenView) {
        _contenView = [[UIView alloc] initWithFrame:CGRectMake(0,20,WIDTH,44)];
    }
    return _contenView;
}

- (UIButton *)chatBtn
{
    if (!_chatBtn) {
        _chatBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_chatBtn setImage:[UIImage imageNamed:@"home_chat"] forState:UIControlStateNormal];
        [[_chatBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) {
            
        }];
    }
    return _chatBtn;
}

- (UIButton *)searchBtn
{
    if (!_searchBtn) {
        _searchBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_searchBtn setImage:[UIImage imageNamed:@"kW_home_search"] forState:UIControlStateNormal];
        [_searchBtn setImage:[UIImage imageNamed:@"kW_home_search"] forState:UIControlStateHighlighted];
        
        @weakify(self);
        [[_searchBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) {
            @strongify(self);
            if (self.searchBlock) {
                self.searchBlock(_searchBtn);
            }
        }];
    }
    return _searchBtn;
}

- (UIButton *)locationBtn
{
    if (!_locationBtn) {
        _locationBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_locationBtn setImage:[UIImage imageNamed:@"home_location_down"] forState:UIControlStateNormal];
        [_locationBtn setTitle:@"定位" forState:UIControlStateNormal];
        [_locationBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _locationBtn.titleLabel.font = FONT(15);
        _locationBtn.imageEdgeInsets = UIEdgeInsetsMake(0,30,0,0);
        _locationBtn.titleEdgeInsets = UIEdgeInsetsMake(0,-30,0,0);
        
        @weakify(self);
        [[_locationBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) {
            @strongify(self);
            if (self.locationBlock) {
                self.locationBlock(_locationBtn);
            }
        }];
    }
    return _locationBtn;
}


@end
